package com.leet.code.simple_array;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: WYG
 * @time: 2020/11/26 19:35
 */

public class LargeGroupPositions {

    public static void main(String[] args) {
        List<List<Integer>> res = new ArrayList<>();
    }

    public List<List<Integer>> largeGroupPositions(String s) {
        List<List<Integer>> res = new ArrayList<>();
        int temp = 0;
        int left = 0;
        int right = 0;
        for (int i = 0; i < s.length() - 1; i++) {
            if (s.substring(i, i+1).equals(s.substring(i+1, i+2))) {
                // System.out.println(left + ":" + right);
                if (temp == 0) left = i;
                temp++;
                if (temp >= 2) {
                    right = i + 1;
                }
                if (temp >= 2 && i == s.length() - 2) {
                    List<Integer> group = new ArrayList<>();
                    group.add(left);
                    group.add(right);
                    res.add(group);
                }
            } else {
                if (temp >= 2) {
                    // System.out.println(left + ":" + right);
                    List<Integer> group = new ArrayList<>();
                    group.add(left);
                    group.add(right);
                    res.add(group);
                }
                temp = 0;
                left = right = 0;
            }
        }
        return res;
    }

}
